package com.extremelylargepackage.entity;

import android.util.Log;

import com.extremelylargepackage.GameResources;

public class BeamWeapon extends Weapon
{
	protected int _beamLength;
	protected int _currentParticle;
	protected boolean _firing;
	protected long _timeSinceLastParticle;

	@Override
	public void fire()
	{
		super.fire();
		//Begin a new stream of fire.
		if(_timeSinceLastShot == 0 && !_firing)
		{
			_firing = true;
			_currentParticle = 0;
			_timeSinceLastParticle = 0;
		}
		//Continue the stream of fire, trick superclass into thinking this is one continuous shot.
		else if(_timeSinceLastShot == 0)
		{
			_currentParticle++;
			_timeSinceLastParticle = 0;
			Log.d("Current Particle", ""+_currentParticle);
		}
	}
	
	@Override
	public void updateState(long time)
	{
		super.updateState(time);
		if(_firing)
		{
			_timeSinceLastParticle += time;
			Log.d("time since last part", ""+_timeSinceLastParticle);
		}
		
		//Fire the next particle so that half of each particle overlaps.
		if(_firing && (_timeSinceLastParticle / 1000f) * _projectile._speed > _projectile.getHeight() / 2)
		{
			Log.d("dist part travelled", ""+(_timeSinceLastParticle / 1000f) * _projectile._speed * GameResources.SCREEN_HEIGHT );
			fire();
			if(_currentParticle >= _beamLength - 1)
				_firing = false;
		}
	}
	
	@Override
	public Object clone()
	{
		BeamWeapon copy = new BeamWeapon();
		setClonedProps(copy);
		copy._beamLength = _beamLength;
		return copy;
	}
}
